function [tradeprice contradiction streak] = processsignals(signals,q)

    % This function parses the strings of signals read from the config file
    % to produce the necessary information - price, whether the signals end
    % in a streak or not, and if there was ever a contradictory signal.
    
    % The input is a cell array of strings.
    
    numrows = size(signals,1);
    tradeprice = zeros(numrows,1);
    contradiction = zeros(numrows,1);
    streak = zeros(numrows,1);
    
    for i=1:numrows
        rowsignals = signals{i};
        p = 0.5;  % trade price initialization
        signalarr = []; % signals as an array
        
        for c=1:size(rowsignals,2)-2  % ignore last signal (used to determine which decision matters)
            if rowsignals(c)=='1' || rowsignals(c)=='0'
                signalarr = [signalarr str2num(rowsignals(c))];
                if rowsignals(c)=='1'
                    p = p*q/(p*q+(1-p)*(1-q));
                else
                    p = p*(1-q)/(p*(1-q)+(1-p)*q);
                end;
            end;
        end;
        tradeprice(i) = p; 
        contradiction(i) = ~(sum(signalarr,2)==0 || sum(signalarr,2)==size(signalarr,2));
        
        streaktype = signalarr(size(signalarr,2));  % whether streak ends with 0 or 1 
        broke = 0;
        streak(i) = 1;
        for j=(size(signalarr,2)-1):-1:1
            if (signalarr(j) == streaktype) && (broke == 0)
                streak(i) = streak(i) + 1;
            else
                broke = 1;
            end
        end
    end
    
